package com.dms.vuemusic.controller;

import com.dms.vuemusic.pojo.Music;
import com.dms.vuemusic.service.impl.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.util.List;

@CrossOrigin("*")
@RestController
public class SaveSongController {
    @Autowired
    MusicService musicService;
    @PostMapping("/saveSong")
    public ResponseEntity<String> addSong(String username, String musicName) {
        musicService.insertMusic(new Music(username, musicName));
        System.out.println("111");
        return new ResponseEntity<>(HttpStatus.OK);
    }
    @PostMapping("/delete")
    public ResponseEntity<String> deleteSong(String username, String musicName) {
        musicService.deleteMusic(new Music(username, musicName));
        System.out.println("111");
        return new ResponseEntity<>(HttpStatus.OK);
    }
    @PostMapping("/record")
    @CrossOrigin("*")
    public ResponseEntity<Boolean> recordSong(String username, String musicName) {
        System.out.println("接收到了record请求");
        Music music=musicService.searchRecord(new Music(username, musicName));
        if (music!=null){
            System.out.println("找到了"+musicName);
            return new ResponseEntity<Boolean>(true,HttpStatus.OK);

        }
        return new ResponseEntity<>(HttpStatus.OK);

    }
    @PostMapping("/getSavingSongs")
    public ResponseEntity<List<Music>> getSavingMusic(String username) {
        List<Music> lis=musicService.searchRecordList(username);
        System.out.println(lis);
        return new ResponseEntity<>(lis,HttpStatus.OK);
    }
}
